const view = (title = "", content = "这是一个查看弹窗") => {
  wx.showModal({
    title: title,
    content: content,
    showCancel: false,//是否显示取消按钮
    confirmColor: 'red',//取消文字的颜色
    confirmText: "关闭",//默认是“确定”
    success: function (res) {}
  })
}


const confirm = (title = "", content ="是否确定此操作？", yes=function(){},no=function(){}) => { 
  wx.showModal({
    title: title,
    content: content,
    cancelColor: 'red',//取消文字的颜色
    success: function (res) {
      if (res.confirm) {
        yes(res);
      } else {
        no(res);
      }  
    }
  })
}
/*
* 轻提示
* @params title[string]
*         icon[string] 取值:'success' 'loading' 'none'
*         timeout
* */
const tip = (title="", icon="none",timeout=3000)=>{
  wx.showToast({
    title: title,
    icon: icon,
    duration: timeout
  })
}

const loading = ( success = function () { }, fail = function () { }) => {
  wx.showToast({
    title: "拼命加载中",
    icon: "loading",
    duration:10000,
    success: function(){
      var result = success() || "";
      if (result!=""){
        console.log(result)
        fail();
      }
      wx.hideToast()
    },
    fail: function(){
      console.log("加载失败")
      fail()
    }
  })
}
const modalConfirm = (title = '', content = '') => {
   return new Promise ( (resolve, reject) => {
        wx.showModal({
          title,
          content,
          success: r => {
            if (r.confirm) {
               resolve(r)
            } else { 
              reject(r)
            }  
          }
        })
   })
}
module.exports = {
  confirm: confirm,
  tip: tip,
  loading: loading,
  view: view,
  modalConfirm
}
